import 'package:base_plugin/base_plugin.dart';
import 'package:finance_app/generated/l10n.dart';
import 'package:finance_app/src/widgets/bottom_sheet/year_month_select_bottom_sheet.dart';
import 'package:flutter/material.dart';

mixin YearMonthSelectMixin<T> on BaseProvider<T> {
  DateTime date;

  @override
  void initState() {
    super.initState();
  }

  void onRequestRefresh();

  void onSelectYearMonth() {
    FocusManager.instance.primaryFocus.unfocus();
    obtainContext?.call((context) async {
      final result =
          await showYearMonthSelectBottomSheet(context, S.current.from, date);
      if (result == null) return;
      date = result;

      update();
      checkFromToDateTimeRefresh();
    });
  }

  void checkFromToDateTimeRefresh() {
    if (date == null) return;
    onRequestRefresh();
  }
}
